package main.resources.model;

import java.math.BigInteger;

import main.resources.exceptions.InvalidDateException;
import main.resources.model.entity.moodle.MdlChat;
import main.resources.model.entity.moodle.MdlChoice;
import main.resources.model.entity.moodle.MdlChoiceOption;
import main.resources.model.entity.moodle.MdlContext;
import main.resources.model.entity.moodle.MdlCourse;
import main.resources.model.entity.moodle.MdlCourseCategory;
import main.resources.model.entity.moodle.MdlCourseSection;
import main.resources.model.entity.moodle.MdlForum;
import main.resources.model.entity.moodle.MdlLesson;
import main.resources.useful.Useful;

public class Fabrica {
	
	public static MdlCourseCategory criarCategoria(String nome, String descricao) {
		MdlCourseCategory category = new MdlCourseCategory();		
		category.setName(nome);
		category.setDescription(descricao);		
		return category;
	}
	
	public static MdlCourse criarCurso(MdlCourseCategory categoria, String nomeCompleto, String nomeCurto, String data, String numSecoes) throws InvalidDateException {
		MdlCourse curso = new MdlCourse();	
		curso.setCategory(new BigInteger(categoria.getId()));
		curso.setFullname(nomeCompleto); 
		curso.setShortname(nomeCurto);
		curso.setStartdate(new BigInteger(Useful.convertDate(data)));
		curso.setTimecreated(new BigInteger(Useful.convertDate(data)));
		curso.setTimemodified(new BigInteger(Useful.convertDate(data))); 
		curso.setNumsections(Integer.parseInt(numSecoes));
		return curso;
	}

	public static MdlContext criarContexto(String nivel) {		
		MdlContext contexto = new MdlContext();	
		contexto.setContextlevel(new BigInteger(nivel));
		return contexto;
	}

	public static MdlCourseSection criarSecao(MdlCourse curso) {		
		MdlCourseSection secao = new MdlCourseSection();
		secao.setCourse(new BigInteger(curso.getId()));
		secao.setSection(new BigInteger(String.valueOf(curso.getNumsections())));
		return secao;
	}
	
	public static MdlChat criarChat(MdlCourse curso, String nome, String introducao, String data) throws InvalidDateException {		
		MdlChat chat = new MdlChat();
		chat.setCourse(new BigInteger(curso.getId()));
		chat.setName(nome);
		chat.setIntro(introducao);
		chat.setChattime(new BigInteger(Useful.convertDate(data)));
		chat.setTimemodified(new BigInteger(Useful.convertDate(data)));
		return chat;
	}
	
	public static MdlChoice criarEscolha(MdlCourse curso, String nome, String introducao, String data) throws InvalidDateException {		
		MdlChoice choice = new MdlChoice();
		choice.setCourse(new BigInteger(curso.getId()));
		choice.setName(nome);
		choice.setIntro(introducao);
		choice.setTimeopen(new BigInteger(Useful.convertDate(data)));
		choice.setTimeclose(new BigInteger(Useful.convertDate(data)));
		choice.setTimemodified(new BigInteger(Useful.convertDate(data)));
		return choice;
	}
	
	public static MdlChoiceOption criarOpcaoDeEscolha(MdlChoice escolha, String texto, String data) throws InvalidDateException {		
		MdlChoiceOption option = new MdlChoiceOption();
		option.setChoiceid(new BigInteger(escolha.getId()));
		option.setText(texto);
		option.setTimemodified(new BigInteger(Useful.convertDate(data)));
		return option;
	}
	
	public static MdlForum criarForum(MdlCourse curso, String nome, String introducao, String data) throws InvalidDateException {		
		MdlForum forum = new MdlForum();
		forum.setCourse(new BigInteger(curso.getId()));
		forum.setName(nome);
		forum.setIntro(introducao);
		forum.setTimemodified(new BigInteger(Useful.convertDate(data)));
		return forum;
	}
	
	public static MdlLesson criarLicao(MdlCourse curso, String nome, String senha, String data) throws InvalidDateException {		
		MdlLesson lesson = new MdlLesson();
		lesson.setCourse(new BigInteger(curso.getId()));
		lesson.setName(nome);
		lesson.setPassword(senha);
		lesson.setTimemodified(new BigInteger(Useful.convertDate(data)));
		return lesson;
	}
	
}
